#include "stdafx.h"
#include "checkUtil.h"


int CheckUtil::checkInt(char* input)
{
	string strnum = string(input);
	if (!strnum.size())
		return FALSE;
	string::iterator it = strnum.begin();
	for (; it != strnum.end(); it++)
	{
		if (*it<'0' || *it > '9')
		{
			return FALSE;
		}
	}
	return TRUE;
}

 
int CheckUtil::checkPRCID(char* pIDInput)
{
	string strID = string(pIDInput);
	int len = strID.size();
	if (len != 15 && len != 18)
		return FALSE;
	string::iterator it = strID.begin();
	int sum = 0;
	for (; it != strID.end();it++)
	{
		if (!(*it >= '\0' && *it <='9' || *it == 'X'))
		{
			return FALSE;
		}
	}
	int index[10] = {7,9,10,5,8,4,2,1,6,3};
	it = strID.begin();
	for (; it != strID.end()-1; it++)
	{
		sum += (*it - '0')*index[strID.npos % 10];
	}
	it = strID.end()-1;
	int check = sum % 11;
	char checkcode = '0';
	if (check == 11)
		checkcode = 'X';
	else
		checkcode = check + '0';
	if (checkcode == toupper(*it))
		return TRUE;
	return FALSE;
}